package cn.com.bluemoon.daps.api.model.factory;

import cn.com.bluemoon.daps.api.model.RemoteDataModelTableService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.model.dto.DapDataModelTableDto;
import cn.com.bluemoon.daps.model.entity.DapDataModelTable;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

@Component
public class RemoteDataModelTableServiceFallbackFactory implements FallbackFactory<RemoteDataModelTableService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteDataModelTableServiceFallbackFactory.class);

    @Override
    public RemoteDataModelTableService create(Throwable throwable) {
        log.error("模型表服务调用失败:{}", throwable.getMessage());
        return new RemoteDataModelTableService() {

            @Override
            public List<DapDataModelTableDto> getTablePublishInfos(String modelId, int isPublish) {
                return Collections.emptyList();
            }

            @Override
            public ResultBean<Boolean> updateById(String id, DapDataModelTable newTable) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "变更表信息失败");
            }

            @Override
            public ResultBean<Boolean> removeById(String id) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "删除表信息失败");
            }

            @Override
            public ResultBean<String> saveTable(DapDataModelTable newTable) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "保存表信息失败");
            }

            @Override
            public ResultBean<List<DapDataModelTable>> listByModelIdAndNewest(String modelId, boolean newest) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "获取表列表数据失败");
            }

            @Override
            public ResultBean<Boolean> updateTableTime(String modelId, String tableId) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "更新表时间失败");
            }

            @Override
            public ResultBean<Boolean> getTopicTable(String topicId) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "获取表信息失败");
            }

            @Override
            public  ResultBean<List<DapDataModelTable>> getTableList(List<String> tableIds) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "获取表信息失败");
            }

            @Override
            public ResultBean<List<String>> findTableInfo(String modelId, String tableName, String fieldName) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "获取模型表和字段id失败");
            }

        };
    }
}
